//
//  ViewController.m
//  IDOLeadingPageController
//
//  Created by 卓勇 on 2017/6/1.
//  Copyright © 2017年 zhuoyong. All rights reserved.
//

#import "ViewController.h"
#import "IDOLeadingPageController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    // 调用方式一
    __weak typeof(self) __weakSelf = self;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [__weakSelf buttonClick:nil];
    });
    
    // 调用方式二
    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    button.center = self.view.center;
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)buttonClick:(UIButton *)sender {
    IDOLeadingPageController *leadingPageController = [[IDOLeadingPageController alloc] initWithNumberOfPages:3 setupCellHandler:^(IDOLeadingPageCell *cell, NSIndexPath *indexPath) {
        
        // 设置图片
        cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"LeadingPage_%ld", (long)indexPath.row + 1]];
        
        // 设置按钮
        [cell.finishButton setTitle:@"立即体验" forState:UIControlStateNormal];
        [cell.finishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [cell.finishButton setBackgroundColor:[UIColor lightGrayColor]];
        
    } finishHandler:^(IDOLeadingPageController *leadingPageController, UIButton *finishButton, NSIndexPath *indexPath) {
        
        [leadingPageController dismissViewControllerAnimated:YES completion:nil];
    }];
    // 设置小圆点颜色
    leadingPageController.pageControl.pageIndicatorTintColor = [UIColor yellowColor];
    leadingPageController.pageControl.currentPageIndicatorTintColor = [UIColor purpleColor];
    [self presentViewController:leadingPageController animated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
